package com.ice.cloud.payManagement.config;


import com.ice.cloud.comm.resp.R;
import com.ice.cloud.comm.resp.ReturnCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice   // 它会拦截所有 @RequestMapping 方法抛出的异常
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)  // 定义具体的异常处理方法，Exception.class 表示捕获所有类型的异常
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public R handlerException(Exception e){
        e.printStackTrace();// 把异常输入控制台
        return R.error(ReturnCodeEnum.RC500.getCode(), e.getMessage());
    }
}